package com.ljj.service;

import org.springframework.stereotype.Service;

@Service  // 让Spring管理这个Bean
public class OrderServiceImpl implements OrderService {

    @Override
    public void add(String pname, int number) {
        System.out.println("正在添加商品: " + pname + ", 数量: " + number);
        try {
            Thread.sleep(10); // 模拟耗时操作
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void delete(String pname) {
        System.out.println("正在删除商品: " + pname);
        try {
            Thread.sleep(15);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int find(String pname) {
        int count = (int)(Math.random() * 10); // 随机返回购物车中该商品数量
        System.out.println("商品 " + pname + " 在购物车中有 " + count + " 个");
        try {
            Thread.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return count;
    }
}